<?php
/* @var $this UserController */
/* @var $model User */
/* @var $form CActiveForm */
?>


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'user-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'user_name'); ?>
		<?php echo $form->textField($model,'user_name',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'user_name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'password'); ?>
		<?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>255)); ?>
		<!--<input type="password" id="User_password" name="User[password]" maxlength="255" size="60">-->
		<?php echo $form->error($model,'password'); ?>
	</div>

	<div class="row">
        <?php echo $form->labelEx($model,'retype_password'); ?>
        <input type="password" size="60" maxlength="255" id="retype_password" name="User[retype_password]" value="<?php echo $model->password ?>">
    </div>

	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		<?php echo $form->dropDownList($model,'status',array('0'=>'No','1'=>'Yes')); ?>
		<?php echo $form->error($model,'status'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'roles'); ?>
		<table width="200" border="0">
        	<tbody>
            	<tr>
                	<td>
                		<label >
        					<input type="checkbox" name="roles['ADMIN']" value="ADMIN" id="ADMIN"
        						style="float: left;margin-right: 5px;"
        						<?php if($this->checkRole($model->roles,'ADMIN')) echo 'checked="checked"' ?>
        						>
        					ADMIN
						</label>
                	</td>
                	<td>
			            <label >
        					<input type="checkbox" name="roles['SUPER_ADMIN']" value="SUPER_ADMIN" id="SUPER_ADMIN"
        					style="float: left;margin-right: 5px;"
        					<?php if($this->checkRole($model->roles,'SUPER_ADMIN')) echo 'checked="checked"' ?>
        					>
        					SUPER_ADMIN
						</label>
                	</td>
            	</tr>
        	</tbody>
		</table>
		<?php echo $form->error($model,'roles'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<script>
    $("form#user-form").submit(function() {
        var password=$("#User_password").val();
        var retype_password=$("#retype_password").val();

        if(password!==retype_password){
            alert(" Mật khẩu không khớp, vui lòng nhập lại");
            return false;
        }

        if(password=='' || retype_password=='') return false;


    });
</script>